// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import Vue from 'vue'
import App from './App'
import router from './router'
// import { Message } from 'element-ui';
// console.log(element-ui)
// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
// Vue.use(ElementUI);

// import { HappyScroll } from 'vue-happy-scroll'
// import 'vue-happy-scroll/docs/happy-scroll.css'
// Vue.component('happy-scroll', HappyScroll)

import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)

axios.interceptors.request.use(
	config => {
		// if (localStorage.getItem("token") != null) {
		//   config.headers["token"] = localStorage.getItem("token");
		// }
		config.headers["token"] = localStorage.getItem("token");
		return config;
	},
	err => Promise.reject(err)
);

axios.interceptors.response.use(
	response => {  
		if (response.status === 200) {   
			return Promise.resolve(response); 
		} else {            
			return Promise.reject(response);        
		}    
	},
	error => {      
		if(error.response.status == 401){
			router.push({path:'/login'})
		}else{
			ELEMENT.Message('系统错误')
		}
		return Promise.reject(error.response);
	}
)

if (process.env.NODE_ENV === "development") {
	// Vue.prototype.url = 'http://iot.91haoka.com/api/'
	Vue.prototype.url = 'http://test.91haoka.com:8080/'
	
}
if (process.env.NODE_ENV === "test") {
	// Vue.prototype.url = 'http://iot.91haoka.com/api/'
	Vue.prototype.url = 'http://test.91haoka.com:8080/'
	
}
if (process.env.NODE_ENV === "production") {
	Vue.prototype.url = window.location.origin + '/api3'
}

// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.headers.post['token'] = localStorage.getItem('token')
// axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.headers.get['token'] = localStorage.getItem('token')



Vue.config.productionTip = false

Vue.filter('qu0', (val) => {
	return val.toFixed(2)
})


/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
})
